<?php
/*
 * 
 *  AJAX
 * 
 * */

class AjaxController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */

    }

    //鼠标悬停弹出
    public function indexAction()
    {
    	$mod 	  = $this->_request->getParam('mod');
		$request  = $this->_request->getParam('request');
		$callback = $this->_request->getParam('callback');

		

		if ($mod == "wow"){
			$item = new Model_Dbtable_Wowitem();
			$spell = new Model_Dbtable_Wowspell();
			
			//item?id=86130  .. npc?id=300
			$source = explode('?id=', $request);
			//$table  = "db_".$mod."_".$source[0];
			
			$what_db = explode('wow/', $source[0]); //判断 DB
			

			if ($what_db[1] == "item"){
				$row = $item->showitem($source[1]);
				
				$row[specs] = preg_replace("/tip/i", "", $row[specs]);
				$row[specs] = preg_replace("/frame/i", "", $row[specs]);
				$tmp = "<li class=\"$row[item_color]\" style=\"font-size:18px;font-weight: bolder;\">$row->name</li>".$row[specs];
				$specs = "<ul class=\"tooltip_show\">".$tmp."</ul>";
			}
			if ($what_db[1] == "spell"){
				$row = $spell->showitem($source[1]);
				
				$specs = "<li class=\"q1\" style=\"font-size:18px;font-weight: bolder;list-style:none;\">$row->name</li>".$row[specs];
			}
			
			
  			$data = array(
  				"data" 			=> $specs,
  				"icon" 			=> DB_URL.$row[icon],
  				"iconWidth" 	=> "56px",
  				"iconHeight" 	=> "56px",
  				"url"			=> "$source[1]",
  				"iframe"		=> true,
  				"width"			=> "auto",
  				"lockable"		=> true,
  				"defaultStyle"	=> true,
  				"css"			=> ""
  			);
  			echo $callback."(".json_encode($data).")";  	
  			exit();	
		}
    }

  
    //autocomplate
    public function searchAction()
    {
    	$mod   = $this->_request->getParam('mod');
    	$query = trim(strip_tags($this->_request->getParam('query')));

    	if ($mod == "wow"){
			$db = new Model_Dbtable_Wowitem();
			$data = $db->ajaxsearch($query);
    	}
    	echo json_encode($data);
    	exit();
    }
    
}

